/*   1:    */ package org.jetbrains.debugger.connection;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.ActionCallback.Done;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.EventDispatcher;
import com.intellij.util.io.socketConnection.ConnectionState;
import com.intellij.util.io.socketConnection.ConnectionStatus;
import com.intellij.util.io.socketConnection.SocketConnectionListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.debugger.DebugEventListener;
import org.jetbrains.debugger.Vm;

import javax.swing.event.HyperlinkListener;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */ 
/*  19:    */ public abstract class VmConnection<T extends Vm>
/*  20:    */   implements Disposable, BrowserConnection
/*  21:    */ {
/*  22: 20 */   private final AtomicReference<ConnectionState> a = new AtomicReference(new ConnectionState(ConnectionStatus.NOT_CONNECTED));
/*  23: 21 */   private final EventDispatcher<DebugEventListener> b = EventDispatcher.create(DebugEventListener.class);
/*  24: 22 */   private final EventDispatcher<SocketConnectionListener> c = EventDispatcher.create(SocketConnectionListener.class);
/*  25:    */   protected volatile T vm;
/*  26: 26 */   private final ActionCallback d = new ActionCallback();
/*  27: 28 */   private final AtomicBoolean e = new AtomicBoolean();
/*  28:    */   
/*  29:    */   public final Vm getVm()
/*  30:    */   {
/*  31: 31 */     return this.vm;
/*  32:    */   }
/*  33:    */   
/*  34:    */   @NotNull
/*  35:    */   public ConnectionState getState()
/*  36:    */   {
/*  37: 37 */     ConnectionState tmp10_7 = ((ConnectionState)this.a.get());
/*  38: 37 */     if (tmp10_7 == null) {
/*  39: 37 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/debugger/connection/VmConnection", "getState" }));
/*  40:    */     }
/*  41: 37 */     return tmp10_7;
/*  42:    */   }
/*  43:    */   
/*  44:    */   public void addDebugListener(@NotNull DebugEventListener paramDebugEventListener, @NotNull Disposable paramDisposable)
/*  45:    */   {
/*  46: 41 */     if (paramDebugEventListener == null) {
/*  47: 41 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/VmConnection", "addDebugListener" }));
/*  48:    */     }
/*  49: 41 */     if (paramDisposable == null) {
/*  50: 41 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/connection/VmConnection", "addDebugListener" }));
/*  51:    */     }
/*  52: 41 */     this.b.addListener(paramDebugEventListener, paramDisposable);
/*  53:    */   }
/*  54:    */   
/*  55:    */   public void executeOnStart(@NotNull Runnable paramRunnable)
/*  56:    */   {
/*  57: 46 */     if (paramRunnable == null) {
/*  58: 46 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/VmConnection", "executeOnStart" }));
/*  59:    */     }
/*  60: 46 */     this.d.doWhenDone(paramRunnable);
/*  61:    */   }
/*  62:    */   
/*  63:    */   protected void setState(@NotNull ConnectionStatus paramConnectionStatus, @Nullable String paramString)
/*  64:    */   {
/*  65: 50 */     if (paramConnectionStatus == null) {
/*  66: 50 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/VmConnection", "setState" }));
/*  67:    */     }
/*  68: 50 */     setState(paramConnectionStatus, paramString, null);
/*  69:    */   }
/*  70:    */   
/*  71:    */   protected void setState(@NotNull ConnectionStatus paramConnectionStatus, @Nullable String paramString, @Nullable HyperlinkListener paramHyperlinkListener)
/*  72:    */   {
/*  73: 54 */     if (paramConnectionStatus == null) {
/*  74: 54 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/VmConnection", "setState" }));
/*  75:    */     }
/*  76: 54 */     ConnectionState localConnectionState = (ConnectionState)this.a.getAndSet(new ConnectionState(paramConnectionStatus, paramString, paramHyperlinkListener));
/*  77: 55 */     if ((localConnectionState == null) || (localConnectionState.getStatus() != paramConnectionStatus)) {
/*  78: 56 */       ((SocketConnectionListener)this.c.getMulticaster()).statusChanged(paramConnectionStatus);
/*  79:    */     }
/*  80:    */   }
/*  81:    */   
/*  82:    */   public void addListener(@NotNull SocketConnectionListener paramSocketConnectionListener, @NotNull Disposable paramDisposable)
/*  83:    */   {
/*  84: 62 */     if (paramSocketConnectionListener == null) {
/*  85: 62 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/VmConnection", "addListener" }));
/*  86:    */     }
/*  87: 62 */     if (paramDisposable == null) {
/*  88: 62 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/connection/VmConnection", "addListener" }));
/*  89:    */     }
/*  90: 62 */     this.c.addListener(paramSocketConnectionListener, paramDisposable);
/*  91:    */   }
/*  92:    */   
/*  93:    */   public DebugEventListener getDebugEventListener()
/*  94:    */   {
/*  95: 66 */     return (DebugEventListener)this.b.getMulticaster();
/*  96:    */   }
/*  97:    */   
/*  98:    */   protected void startProcessing()
/*  99:    */   {
/* 100: 70 */     this.d.setDone();
/* 101:    */   }
/* 102:    */   
/* 103:    */   public final void close(@Nullable String paramString)
/* 104:    */   {
/* 105: 74 */     if (!this.e.compareAndSet(false, true)) {
/* 106: 75 */       return;
/* 107:    */     }
/* 108: 78 */     this.vm = null;
/* 109: 79 */     if (!this.d.isProcessed()) {
/* 110: 80 */       this.d.setRejected();
/* 111:    */     }
/* 112: 82 */     setState(ConnectionStatus.DISCONNECTED, paramString);
/* 113: 83 */     Disposer.dispose(this, false);
/* 114:    */   }
/* 115:    */   
/* 116:    */   public void dispose() {}
/* 117:    */   
/* 118:    */   public ActionCallback detachAndClose()
/* 119:    */   {
/* 120: 91 */     if (!this.d.isProcessed()) {
/* 121: 92 */       this.d.setRejected();
/* 122:    */     }
/* 123: 95 */     Vm localVm = this.vm;
/* 124:    */     Object localObject;
/* 125: 97 */     if (localVm == null)
/* 126:    */     {
/* 127: 98 */       localObject = new ActionCallback.Done();
/* 128:    */     }
/* 129:    */     else
/* 130:    */     {
/* 131:101 */       this.vm = null;
/* 132:102 */       localObject = localVm.detach();
/* 133:    */     }
/* 134:104 */     close(null);
/* 135:105 */     return localObject;
/* 136:    */   }
/* 137:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.debugger.connection.VmConnection

 * JD-Core Version:    0.7.0.1

 */